package com.bristua.barcode.customer.biz;

import com.bristua.barcode.customer.model.TCustomerBindSupplier;
import com.bristua.barcode.customer.model.bo.CustomerBindQRCode;
import com.bristua.barcode.supplier.dao.TQrCodeLimitAmtAdjustmentMapper;
import com.bristua.barcode.supplier.dao.TQrCodeMapper;
import com.bristua.barcode.supplier.model.TQrCode;
import com.bristua.barcode.supplier.model.TQrCodeLimitAmtAdjustment;
import com.bristua.barcode.supplier.model.condition.TQrCodeLimitAmtAdjustmentExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/8/15.
 */
@Service
public class GetCustomerBindQRCodeBiz {
    @Resource
    private TQrCodeMapper tQrCodeMapper;
    @Resource
    private TQrCodeLimitAmtAdjustmentMapper tQrCodeLimitAmtAdjustmentMapper;

    public CustomerBindQRCode getCustomerBindQRCode(String customerId, TCustomerBindSupplier tCustomerBindSupplier) {
        CustomerBindQRCode customerBindQRCode = new CustomerBindQRCode();
        customerBindQRCode.setSupplierId(tCustomerBindSupplier.getSupplierId());
        customerBindQRCode.setQrCodeId(tCustomerBindSupplier.getQrCodeId());
        TQrCode tQrCode = tQrCodeMapper.selectByPrimaryKey(tCustomerBindSupplier.getQrCodeId());
        customerBindQRCode.setQrCodeUrl(tQrCode.getQrCodeUrl());

        TQrCodeLimitAmtAdjustmentExample tQrCodeLimitAmtAdjustmentExample = new TQrCodeLimitAmtAdjustmentExample();
        tQrCodeLimitAmtAdjustmentExample.createCriteria().andQrCodeIdEqualTo(tCustomerBindSupplier.getQrCodeId()).andCustomerIdEqualTo(customerId);
        tQrCodeLimitAmtAdjustmentExample.setOrderByClause("desc create_time");

        List<TQrCodeLimitAmtAdjustment> tQrCodeLimitAmtAdjustmentList = tQrCodeLimitAmtAdjustmentMapper.selectByExample(tQrCodeLimitAmtAdjustmentExample);
        if(tQrCodeLimitAmtAdjustmentList!=null && tQrCodeLimitAmtAdjustmentList.size()>0){
            TQrCodeLimitAmtAdjustment tQrCodeLimitAmtAdjustment = tQrCodeLimitAmtAdjustmentList.get(0);
            customerBindQRCode.setLimitAmt(String.valueOf(tQrCodeLimitAmtAdjustment.getLimitAmt()));
            customerBindQRCode.setFlowTotalAmt(String.valueOf(tQrCodeLimitAmtAdjustment.getFlowTotalAmt()));
            customerBindQRCode.setQrCodeLimitId(tQrCodeLimitAmtAdjustment.getQrCodeLimtAmtId());
        }
        return customerBindQRCode;
    }
}
